package com.itheima.servlet.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;

// req.html
// 演示Request通用方式获取请求参数
@WebServlet("/req03")
public class RequestDemo03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1.Map<String, String[]> getParameterMap()：获取所有参数Map集合
        Map<String, String[]> userMap = req.getParameterMap();
        Set<String> KeySet = userMap.keySet();
        for (String Ket : KeySet) {
            String[] velue = userMap.get(Ket);
            System.out.println("key:"+Ket+"::"+"velue:"+Arrays.toString(velue));
        }

        System.out.println("--------------------------------------");
        // 2.String getParameter(String name)：根据名称获取参数值（单个值）
        String parameter = req.getParameter("username");
        System.out.println(" username = " + parameter);
        System.out.println("--------------------------------------");
        // 3.String[] getParameterValues(String name) ：根据名称获取参数值（数组）
        String[] values = req.getParameterValues("hobby");
        System.out.println("hoddy = " + Arrays.toString(values));

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doPost");

        doGet(req,resp);
        // 1.Map<String, String[]> getParameterMap()：获取所有参数Map集合


        System.out.println("--------------------------------------");
        // 2.String getParameter(String name)：根据名称获取参数值（单个值）


        System.out.println("--------------------------------------");
        // 3.String[] getParameterValues(String name) ：根据名称获取参数值（数组）

    }
}
